home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Hello / Sources / HelloCmd.cpp next >
Encoding:
Text File  |  1995-11-08  |  8.5 KB  |  273 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                HelloCmd.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Hello.hpp"
  13.  
  14. #ifndef HELLOCMD_H
  15. #include "HelloCmd.h"
  16. #endif
  17.  
  18. #ifndef HELLOPRT_H
  19. #include "HelloPrt.h"
  20. #endif
  21.  
  22. // ----- Framework Includes -----
  23.  
  24. #ifndef FWPRESEN_H
  25. #include "FWPresen.h"
  26. #endif
  27.  
  28. // ----- OpenDoc Includes -----
  29.  
  30. #ifndef SOM_Module_OpenDoc_Commands_defined
  31. #include <CmdDefs.xh>
  32. #endif
  33.  
  34. //========================================================================================
  35. // RunTime Info
  36. //========================================================================================
  37.  
  38. #ifdef FW_BUILD_MAC
  39. #pragma segment odfhello
  40. #endif
  41.  
  42. //========================================================================================
  43. // CHelloEditCommand
  44. //========================================================================================
  45.  
  46. //----------------------------------------------------------------------------------------
  47. //    CHelloEditCommand constructor
  48. //----------------------------------------------------------------------------------------
  49.  
  50. CHelloEditCommand::CHelloEditCommand(Environment* ev,
  51.                                      ODCommandID id,
  52.                                      CHelloPart* itsPart,
  53.                                      FW_CFrame* frame) :
  54.     FW_CEditCommand(ev, id, frame, FW_kCanUndo),
  55.     fHelloPart(itsPart)
  56. {
  57. }
  58.  
  59. //----------------------------------------------------------------------------------------
  60. //    CHelloEditCommand destructor
  61. //----------------------------------------------------------------------------------------
  62.  
  63. CHelloEditCommand::~CHelloEditCommand()
  64. {
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. //    CHelloEditCommand::SaveUndoState
  69. //----------------------------------------------------------------------------------------
  70.  
  71. void CHelloEditCommand::SaveUndoState(Environment *ev)    // Override
  72. {
  73.      fHelloPart->GetData(ev, fSavedSetting, fSavedTextData);
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    CHelloEditCommand::UndoIt
  78. //----------------------------------------------------------------------------------------
  79.  
  80. void CHelloEditCommand::UndoIt(Environment* ev)
  81. {
  82.     FW_CEditCommand::UndoIt(ev);    // call inherited
  83.  
  84.     switch (fCommandID)
  85.     {
  86.         case kODCommandCut:
  87.         case kODCommandClear:
  88.             this->RestoreSelection(ev);
  89.             break;
  90.  
  91.         case kODCommandPaste:
  92.             this->SwapSelection(ev);
  93.             break;
  94.     }    
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. //    CHelloEditCommand::RedoIt
  99. //----------------------------------------------------------------------------------------
  100.  
  101. void CHelloEditCommand::RedoIt(Environment *ev)    // Override
  102. {
  103.     FW_CEditCommand::RedoIt(ev);    // call inherited
  104.  
  105.     switch (fCommandID)
  106.     {
  107.         case kODCommandCut:
  108.         case kODCommandClear:
  109.             this->RemoveSelection(ev);
  110.             break;
  111.  
  112.         case kODCommandPaste:
  113.             this->SwapSelection(ev);
  114.             break;
  115.     }    
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. //    CHelloEditCommand::RemoveSelection
  120. //----------------------------------------------------------------------------------------
  121.  
  122. void CHelloEditCommand::RemoveSelection(Environment* ev)
  123. {
  124.     fHelloPart->ClearData(ev, fSavedSetting);
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    CHelloEditCommand::RestoreSelection
  129. //----------------------------------------------------------------------------------------
  130.  
  131. void CHelloEditCommand::RestoreSelection(Environment* ev)
  132. {
  133.     fHelloPart->SetData(ev, fSavedSetting, fSavedTextData);
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    CHelloEditCommand::SwapSelection
  138. //----------------------------------------------------------------------------------------
  139.  
  140. void CHelloEditCommand::SwapSelection(Environment* ev)
  141. {
  142.     FW_CString255 textData;
  143.     FW_Boolean setting;
  144.     fHelloPart->GetData(ev, setting, textData);
  145.     fHelloPart->SetData(ev, fSavedSetting, fSavedTextData);
  146.     fSavedSetting = setting;
  147.     fSavedTextData = textData;
  148. }
  149.  
  150. //========================================================================================
  151. // CHelloDragCommand
  152. //========================================================================================
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    CHelloDragCommand constructor
  156. //----------------------------------------------------------------------------------------
  157.  
  158. CHelloDragCommand::CHelloDragCommand(Environment* ev,
  159.                                      CHelloPart* part,
  160.                                      FW_CFrame* frame) :
  161.     FW_CDragCommand(ev, frame, FW_kCanUndo),
  162.     fHelloPart(part)
  163. {
  164.     this->SetMenuStrings(ev, "Undo Move", "Redo Move");
  165.     FW_END_CONSTRUCTOR
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    CHelloDragCommand destructor
  170. //----------------------------------------------------------------------------------------
  171.  
  172. CHelloDragCommand::~CHelloDragCommand()
  173. {
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    CHelloDragCommand::SaveUndoState
  178. //----------------------------------------------------------------------------------------
  179.  
  180. void CHelloDragCommand::SaveUndoState(Environment *ev)    // Override
  181. {
  182.      fHelloPart->GetData(ev, fSavedSetting, fSavedTextData);
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    CHelloDragCommand::UndoIt
  187. //----------------------------------------------------------------------------------------
  188.  
  189. void CHelloDragCommand::UndoIt(Environment* ev)
  190. {
  191.     fHelloPart->SetData(ev, fSavedSetting, fSavedTextData);
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. //    CHelloDragCommand::RedoIt
  196. //----------------------------------------------------------------------------------------
  197.  
  198. void CHelloDragCommand::RedoIt(Environment* ev)
  199. {
  200.     fHelloPart->ClearData(ev, fSavedSetting);
  201. }
  202.  
  203. //========================================================================================
  204. // CHelloDropCommand
  205. //========================================================================================
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    CHelloDropCommand constructor
  209. //----------------------------------------------------------------------------------------
  210.  
  211. CHelloDropCommand::CHelloDropCommand(Environment *ev,
  212.                                      CHelloPart* itsPart,
  213.                                      FW_CFrame* frame,
  214.                                      ODDragItemIterator* dropInfo, 
  215.                                      ODFacet* odFacet,
  216.                                      const FW_CPoint& dropPoint) : 
  217.     FW_CDropCommand(ev, itsPart, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
  218.     fHelloPart(itsPart)
  219. {
  220.     this->SetMenuStrings(ev, "Undo Drop", "Redo Drop");
  221.     FW_END_CONSTRUCTOR
  222. }
  223.  
  224. //----------------------------------------------------------------------------------------
  225. //    CHelloDropCommand destructor
  226. //----------------------------------------------------------------------------------------
  227.  
  228. CHelloDropCommand::~CHelloDropCommand()
  229. {
  230. }
  231.  
  232. //----------------------------------------------------------------------------------------
  233. //    CHelloDropCommand::SaveUndoState
  234. //----------------------------------------------------------------------------------------
  235.  
  236. void CHelloDropCommand::SaveUndoState(Environment *ev)    // Override
  237. {
  238.      fHelloPart->GetData(ev, fSavedSetting, fSavedTextData);
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242. //    CHelloDropCommand::UndoIt
  243. //----------------------------------------------------------------------------------------
  244.  
  245. void CHelloDropCommand::UndoIt(Environment* ev)
  246. {
  247.     this->SwapSelection(ev);
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    CHelloDropCommand::RedoIt
  252. //----------------------------------------------------------------------------------------
  253.  
  254. void CHelloDropCommand::RedoIt(Environment* ev)
  255. {
  256.     this->SwapSelection(ev);
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    CHelloDropCommand::SwapSelection
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void CHelloDropCommand::SwapSelection(Environment* ev)
  264. {
  265.     FW_CString255 textData;
  266.     FW_Boolean setting;
  267.     fHelloPart->GetData(ev, setting, textData);
  268.     fHelloPart->SetData(ev, fSavedSetting, fSavedTextData);
  269.     fSavedSetting = setting;
  270.     fSavedTextData = textData;
  271. }
  272.  
  273.